//
// Copyright (C) 2011 - 2013  Steve Channell steve.channell@cepheis.com
//
// This file is part of Cephei.QL, an open-source library wrapper 
// arround QuantLib http://quantlib.org/
//
// Cephei.QL is open source software: you can redistribute it and/or modify it
// under the terms of the license.  You should have received a
// copy of the license along with this program; if not, please email
// <support@cepheis.com>. The license is also available online at
// <http://cepheis.com/license.htm>.
//
// This program is distributed in the hope that it will be useful, but WITHOUT
// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
// FOR A PARTICULAR PURPOSE.  See the license for more details.
//
// Version 2.2 with QuantLib 1.2.1
//#include "stdafx.h"
#include "SpreadedSwaptionVolatility.h"
using namespace Cephei::QL::Termstructures::Volatility::Swaption;
#include <gen/QL/Times/Calendar.h>
#include <gen/QL/Times/DayCounter.h>
#include <gen/QL/Times/Period.h>
#include <gen/QL/Quote.h>
#include <gen/QL/Termstructures/VolatilityTermStructure.h>
using namespace Cephei::QL::Times;
using namespace Cephei::QL;
using namespace Cephei::QL::Termstructures;
#define HANDLE
#undef ABSTRACT
#undef STRUCT
Cephei::QL::Termstructures::Volatility::Swaption::CSpreadedSwaptionVolatility::CSpreadedSwaptionVolatility (boost::shared_ptr<QuantLib::SpreadedSwaptionVolatility>& childNative, Object^ owner) : CVolatilityTermStructure(CSpreadedSwaptionVolatility::typeid)
{
#ifdef HANDLE
	_phSpreadedSwaptionVolatility = NULL;
#endif
	_ppSpreadedSwaptionVolatility = &childNative;
    _ppVolatilityTermStructure = new boost::shared_ptr<QuantLib::VolatilityTermStructure> (boost::dynamic_pointer_cast<QuantLib::VolatilityTermStructure> (*_ppSpreadedSwaptionVolatility));
}
Cephei::QL::Termstructures::Volatility::Swaption::CSpreadedSwaptionVolatility::CSpreadedSwaptionVolatility (QuantLib::SpreadedSwaptionVolatility& childNative, Object^ owner) : CVolatilityTermStructure(CSpreadedSwaptionVolatility::typeid)
{
#ifdef HANDLE
	_phSpreadedSwaptionVolatility = NULL;
#endif
	_ppSpreadedSwaptionVolatility = new boost::shared_ptr<QuantLib::SpreadedSwaptionVolatility> (&childNative);
    _ppVolatilityTermStructure = new boost::shared_ptr<QuantLib::VolatilityTermStructure> (boost::dynamic_pointer_cast<QuantLib::VolatilityTermStructure> (*_ppSpreadedSwaptionVolatility));
    _SpreadedSwaptionVolatilityOwner = owner;
    _VolatilityTermStructureOwner = owner;
}

Cephei::QL::Termstructures::Volatility::Swaption::CSpreadedSwaptionVolatility::CSpreadedSwaptionVolatility (CSpreadedSwaptionVolatility^ copy) : CVolatilityTermStructure(CSpreadedSwaptionVolatility::typeid)
{
#ifdef HANDLE
	_phSpreadedSwaptionVolatility = NULL;
#endif
	if (copy->HasNative() != NULL)
    {
		_ppSpreadedSwaptionVolatility = new boost::shared_ptr<QuantLib::SpreadedSwaptionVolatility> (copy->GetShared());
        _ppVolatilityTermStructure = new boost::shared_ptr<QuantLib::VolatilityTermStructure> (boost::dynamic_pointer_cast<QuantLib::VolatilityTermStructure> (*_ppSpreadedSwaptionVolatility));
    }
}
Cephei::QL::Termstructures::Volatility::Swaption::CSpreadedSwaptionVolatility::CSpreadedSwaptionVolatility (PLATFORM::Type^ t) : CVolatilityTermStructure(CSpreadedSwaptionVolatility::typeid)
{
#ifdef HANDLE
	_phSpreadedSwaptionVolatility = NULL;
#endif
	if (!t->IsSubclassOf(CSpreadedSwaptionVolatility::typeid))
		throw REFNEW Exception ("Invalid base-case init");
}
#ifdef HANDLE
Cephei::QL::Termstructures::Volatility::Swaption::CSpreadedSwaptionVolatility::CSpreadedSwaptionVolatility (QuantLib::Handle<QuantLib::SpreadedSwaptionVolatility>& childNative, Object^ owner)  : CVolatilityTermStructure(CSpreadedSwaptionVolatility::typeid)
{
	_phSpreadedSwaptionVolatility = &childNative;
	_ppSpreadedSwaptionVolatility = &static_cast<boost::shared_ptr<QuantLib::SpreadedSwaptionVolatility>>(childNative.currentLink());
    _ppVolatilityTermStructure = new boost::shared_ptr<QuantLib::VolatilityTermStructure> (boost::dynamic_pointer_cast<QuantLib::VolatilityTermStructure> (*_ppSpreadedSwaptionVolatility));
    _SpreadedSwaptionVolatilityOwner = owner;
}
Cephei::QL::Termstructures::Volatility::Swaption::CSpreadedSwaptionVolatility::CSpreadedSwaptionVolatility (QuantLib::Handle<QuantLib::SpreadedSwaptionVolatility> childNative)  : CVolatilityTermStructure(CSpreadedSwaptionVolatility::typeid)
{
	_phSpreadedSwaptionVolatility = &childNative;
	_ppSpreadedSwaptionVolatility = &static_cast<boost::shared_ptr<QuantLib::SpreadedSwaptionVolatility>>(childNative.currentLink());
    _ppVolatilityTermStructure = new boost::shared_ptr<QuantLib::VolatilityTermStructure> (boost::dynamic_pointer_cast<QuantLib::VolatilityTermStructure> (*_ppSpreadedSwaptionVolatility));
}
#endif
#ifdef STRUCT
Cephei::QL::Termstructures::Volatility::Swaption::CSpreadedSwaptionVolatility::CSpreadedSwaptionVolatility (QuantLib::SpreadedSwaptionVolatility childNative)  : CVolatilityTermStructure(CSpreadedSwaptionVolatility::typeid)
{
#ifdef HANDLE
	_phSpreadedSwaptionVolatility = NULL;
#endif
	_ppSpreadedSwaptionVolatility = new boost::shared_ptr<QuantLib::SpreadedSwaptionVolatility> (new QuantLib::SpreadedSwaptionVolatility (childNative));
    _ppVolatilityTermStructure = new boost::shared_ptr<QuantLib::VolatilityTermStructure> (boost::dynamic_pointer_cast<QuantLib::VolatilityTermStructure> (*_ppSpreadedSwaptionVolatility));
}
#endif

Cephei::QL::Termstructures::Volatility::Swaption::CSpreadedSwaptionVolatility::~CSpreadedSwaptionVolatility ()
{
    if (_ppSpreadedSwaptionVolatility != NULL)
    {
	    delete _ppSpreadedSwaptionVolatility;
        _ppSpreadedSwaptionVolatility = NULL;
    }
}
Cephei::QL::Termstructures::Volatility::Swaption::CSpreadedSwaptionVolatility::!CSpreadedSwaptionVolatility ()
{
    if (_ppSpreadedSwaptionVolatility != NULL)
    {
	    delete _ppSpreadedSwaptionVolatility;
    }
}
QuantLib::SpreadedSwaptionVolatility& Cephei::QL::Termstructures::Volatility::Swaption::CSpreadedSwaptionVolatility::GetReference ()
{
    if (_ppSpreadedSwaptionVolatility == NULL) throw REFNEW NativeNullException ();
	return **_ppSpreadedSwaptionVolatility;
}
boost::shared_ptr<QuantLib::SpreadedSwaptionVolatility>& Cephei::QL::Termstructures::Volatility::Swaption::CSpreadedSwaptionVolatility::GetShared ()
{
    if (_ppSpreadedSwaptionVolatility == NULL) throw REFNEW NativeNullException ();
	return *_ppSpreadedSwaptionVolatility;
}
QuantLib::SpreadedSwaptionVolatility* Cephei::QL::Termstructures::Volatility::Swaption::CSpreadedSwaptionVolatility::GetPointer ()
{
    if (_ppSpreadedSwaptionVolatility == NULL) throw REFNEW NativeNullException ();
	return &**_ppSpreadedSwaptionVolatility;
}
#ifdef HANDLE
QuantLib::Handle<QuantLib::SpreadedSwaptionVolatility>& Cephei::QL::Termstructures::Volatility::Swaption::CSpreadedSwaptionVolatility::GetHandle ()
{
	if (_phSpreadedSwaptionVolatility == NULL)
	{
		_phSpreadedSwaptionVolatility = new Handle<QuantLib::SpreadedSwaptionVolatility> (*_ppSpreadedSwaptionVolatility);
	}
	return *_phSpreadedSwaptionVolatility;
}
#endif
bool Cephei::QL::Termstructures::Volatility::Swaption::CSpreadedSwaptionVolatility::HasNative () 
{
	return (_ppSpreadedSwaptionVolatility != NULL);
}

Cephei::QL::Times::ICalendar^ Cephei::QL::Termstructures::Volatility::Swaption::CSpreadedSwaptionVolatility::Calendar::get ()
{
    try
    {
    	QuantLib::Calendar _rv = (QuantLib::Calendar)(*_ppSpreadedSwaptionVolatility)->calendar ( );   
        Cephei::QL::Times::CCalendar^ _nrv = REFNEW Cephei::QL::Times::CCalendar (_rv);
    	return _nrv;
	}
    catch (QuantLib::Error& _error)
    {
        if (_error.what())
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String(_error.what()));
        else
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String("Unknown quantlib error"));
        
    }
	catch (std::exception& _error)
	{
        if (_error.what())
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String(_error.what()));
        else
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String("Unknown std::exception"));
	}
    finally
    {
    }
}
Cephei::QL::Times::IDayCounter^ Cephei::QL::Termstructures::Volatility::Swaption::CSpreadedSwaptionVolatility::DayCounter::get ()
{
    try
    {
    	QuantLib::DayCounter _rv = (QuantLib::DayCounter)(*_ppSpreadedSwaptionVolatility)->dayCounter ( );   
        Cephei::QL::Times::CDayCounter^ _nrv = REFNEW Cephei::QL::Times::CDayCounter (_rv);
    	return _nrv;
	}
    catch (QuantLib::Error& _error)
    {
        if (_error.what())
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String(_error.what()));
        else
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String("Unknown quantlib error"));
        
    }
	catch (std::exception& _error)
	{
        if (_error.what())
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String(_error.what()));
        else
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String("Unknown std::exception"));
	}
    finally
    {
    }
}
DateTime Cephei::QL::Termstructures::Volatility::Swaption::CSpreadedSwaptionVolatility::MaxDate::get ()
{
    try
    {
    	QuantLib::Date _rv = (QuantLib::Date)(*_ppSpreadedSwaptionVolatility)->maxDate ( );   
        DateTime _nrv = (DateTime)ValueHelper::Convert (_rv); //c
    	return _nrv;
	}
    catch (QuantLib::Error& _error)
    {
        if (_error.what())
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String(_error.what()));
        else
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String("Unknown quantlib error"));
        
    }
	catch (std::exception& _error)
	{
        if (_error.what())
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String(_error.what()));
        else
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String("Unknown std::exception"));
	}
    finally
    {
    }
}
Double Cephei::QL::Termstructures::Volatility::Swaption::CSpreadedSwaptionVolatility::MaxStrike::get ()
{
    try
    {
    	QuantLib::Rate _rv = (QuantLib::Rate)(*_ppSpreadedSwaptionVolatility)->maxStrike ( );   
        Double _nrv = (Double)ValueHelper::Convert (_rv); //c
    	return _nrv;
	}
    catch (QuantLib::Error& _error)
    {
        if (_error.what())
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String(_error.what()));
        else
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String("Unknown quantlib error"));
        
    }
	catch (std::exception& _error)
	{
        if (_error.what())
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String(_error.what()));
        else
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String("Unknown std::exception"));
	}
    finally
    {
    }
}
Cephei::QL::Times::IPeriod^ Cephei::QL::Termstructures::Volatility::Swaption::CSpreadedSwaptionVolatility::MaxSwapTenor::get ()
{
    try
    {
    	QuantLib::Period& _rv = (QuantLib::Period&)(*_ppSpreadedSwaptionVolatility)->maxSwapTenor ( );   
        Cephei::QL::Times::CPeriod^ _nrv = REFNEW Cephei::QL::Times::CPeriod (_rv, this);
    	return _nrv;
	}
    catch (QuantLib::Error& _error)
    {
        if (_error.what())
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String(_error.what()));
        else
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String("Unknown quantlib error"));
        
    }
	catch (std::exception& _error)
	{
        if (_error.what())
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String(_error.what()));
        else
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String("Unknown std::exception"));
	}
    finally
    {
    }
}
Double Cephei::QL::Termstructures::Volatility::Swaption::CSpreadedSwaptionVolatility::MaxTime::get ()
{
    try
    {
    	QuantLib::Time _rv = (QuantLib::Time)(*_ppSpreadedSwaptionVolatility)->maxTime ( );   
        Double _nrv = (Double)ValueHelper::Convert (_rv); //c
    	return _nrv;
	}
    catch (QuantLib::Error& _error)
    {
        if (_error.what())
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String(_error.what()));
        else
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String("Unknown quantlib error"));
        
    }
	catch (std::exception& _error)
	{
        if (_error.what())
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String(_error.what()));
        else
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String("Unknown std::exception"));
	}
    finally
    {
    }
}
Double Cephei::QL::Termstructures::Volatility::Swaption::CSpreadedSwaptionVolatility::MinStrike::get ()
{
    try
    {
    	QuantLib::Rate _rv = (QuantLib::Rate)(*_ppSpreadedSwaptionVolatility)->minStrike ( );   
        Double _nrv = (Double)ValueHelper::Convert (_rv); //c
    	return _nrv;
	}
    catch (QuantLib::Error& _error)
    {
        if (_error.what())
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String(_error.what()));
        else
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String("Unknown quantlib error"));
        
    }
	catch (std::exception& _error)
	{
        if (_error.what())
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String(_error.what()));
        else
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String("Unknown std::exception"));
	}
    finally
    {
    }
}
DateTime Cephei::QL::Termstructures::Volatility::Swaption::CSpreadedSwaptionVolatility::ReferenceDate::get ()
{
    try
    {
    	QuantLib::Date _rv = (QuantLib::Date)(*_ppSpreadedSwaptionVolatility)->referenceDate ( );   
        DateTime _nrv = (DateTime)ValueHelper::Convert (_rv); //c
    	return _nrv;
	}
    catch (QuantLib::Error& _error)
    {
        if (_error.what())
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String(_error.what()));
        else
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String("Unknown quantlib error"));
        
    }
	catch (std::exception& _error)
	{
        if (_error.what())
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String(_error.what()));
        else
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String("Unknown std::exception"));
	}
    finally
    {
    }
}
UInt32 Cephei::QL::Termstructures::Volatility::Swaption::CSpreadedSwaptionVolatility::SettlementDays::get ()
{
    try
    {
    	QuantLib::Natural _rv = (QuantLib::Natural)(*_ppSpreadedSwaptionVolatility)->settlementDays ( );   
        UInt32 _nrv = (UInt32)ValueHelper::Convert (_rv); //c
    	return _nrv;
	}
    catch (QuantLib::Error& _error)
    {
        if (_error.what())
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String(_error.what()));
        else
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String("Unknown quantlib error"));
        
    }
	catch (std::exception& _error)
	{
        if (_error.what())
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String(_error.what()));
        else
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String("Unknown std::exception"));
	}
    finally
    {
    }
}
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// Factory class

